package biz.obake.team.touchprotector.ui;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.b;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.q;
import androidx.viewpager.widget.ViewPager;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.c;
import biz.obake.team.touchprotector.tpservice.TPService;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MainActivity extends androidx.appcompat.app.c implements c.b {
    private ViewPager t;
    private d u = new d(this, (a) null);
    private List<String> v = new ArrayList();
    /* access modifiers changed from: private */
    public Handler w = new Handler();

    class a implements DialogInterface.OnDismissListener {
        a() {
        }

        public void onDismiss(DialogInterface dialogInterface) {
            biz.obake.team.touchprotector.c.u();
            MainActivity.this.N();
        }
    }

    class b implements DialogInterface.OnClickListener {
        b() {
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            biz.obake.team.touchprotector.c.u();
            MainActivity.this.N();
        }
    }

    class c implements Runnable {
        c() {
        }

        public void run() {
            if (biz.obake.team.touchprotector.c.e()) {
                Intent intent = new Intent(MainActivity.this, MainActivity.class);
                intent.setFlags(32768);
                MainActivity.this.startActivity(intent);
                return;
            }
            MainActivity.this.w.postDelayed(this, 500);
        }
    }

    private class d extends q {
        private ArrayList<Fragment> g;
        private ArrayList<Integer> h;

        private d(MainActivity mainActivity) {
            super(mainActivity.m());
            this.g = new ArrayList<>();
            this.h = new ArrayList<>();
        }

        /* synthetic */ d(MainActivity mainActivity, a aVar) {
            this(mainActivity);
        }

        /* access modifiers changed from: private */
        public void t(int i, Fragment fragment) {
            if (!this.g.contains(fragment)) {
                this.g.add(fragment);
                this.h.add(Integer.valueOf(i));
            }
        }

        public int c() {
            return this.g.size();
        }

        public CharSequence e(int i) {
            return (i < 0 || this.h.size() <= i) ? "n/a" : biz.obake.team.touchprotector.c.w(this.h.get(i).intValue());
        }

        public Fragment p(int i) {
            if (i < 0 || this.g.size() <= i) {
                return null;
            }
            return this.g.get(i);
        }
    }

    private void I(int i, String str) {
        int K = K();
        b bVar = new b();
        bVar.c(str, K);
        this.u.t(i, bVar);
        this.v.add(str);
    }

    private int K() {
        int i = 1;
        while (findViewById(i) != null) {
            i++;
        }
        return i;
    }

    public static void M(Map<String, String> map) {
        map.put("MainActivity.State", "Stopped");
    }

    /* access modifiers changed from: private */
    public void N() {
        this.w.removeCallbacksAndMessages((Object) null);
        this.w.postDelayed(new c(), 500);
    }

    public void J() {
        if (!biz.obake.team.touchprotector.c.e()) {
            b.a aVar = new b.a(this, 2131689481);
            aVar.s(R.string.overlay_warning_title);
            aVar.g(R.string.overlay_warning_message);
            aVar.o(R.string.overlay_warning_ok, new b());
            aVar.m(new a());
            aVar.e(R.drawable.ic_launcher);
            aVar.a().show();
        }
    }

    public String L() {
        return this.v.get(this.t.getCurrentItem());
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.ui_main_activity);
        I(R.string.ui_tab_notices_title, "Tab_Notices");
        I(R.string.ui_tab_shake_title, "Tab_Shake");
        I(R.string.ui_tab_proximity_title, "Tab_Proximity");
        I(R.string.ui_tab_upsidedown_title, "Tab_UpsideDown");
        I(R.string.ui_tab_hardkeys_title, "Tab_Hardkeys");
        I(R.string.ui_tab_lockdesign_title, "Tab_LockDesign");
        I(R.string.ui_tab_whilelocked_title, "Tab_WhileLocked");
        I(R.string.ui_tab_notification_title, "Tab_Notification");
        I(R.string.ui_tab_safety_title, "Tab_Safety");
        I(R.string.ui_tab_advanced_title, "Tab_Advanced");
        I(R.string.ui_tab_donation_title, "Tab_Donation");
        I(R.string.ui_tab_about_title, "Tab_About");
        ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        this.t = viewPager;
        viewPager.setAdapter(this.u);
        ((TabLayout) findViewById(R.id.tabs)).setupWithViewPager(this.t);
        biz.obake.team.touchprotector.g.c.e(this);
        J();
    }

    /* access modifiers changed from: protected */
    public void onDestroy() {
        biz.obake.team.touchprotector.g.c.h(this);
        super.onDestroy();
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        biz.obake.team.touchprotector.g.c.g("MainActivity.State", "Paused");
        this.w.removeCallbacksAndMessages((Object) null);
        biz.obake.team.touchprotector.a.a();
    }

    public void onRamPrefsChanged(String str) {
        if (((str.hashCode() == -2066548004 && str.equals("TPService.State")) ? (char) 0 : 65535) == 0 && "Stopped".equals(biz.obake.team.touchprotector.g.c.c("TPService.State"))) {
            finishAndRemoveTask();
        }
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        biz.obake.team.touchprotector.g.c.g("MainActivity.State", "Resumed");
        if ("Stopped".equals(biz.obake.team.touchprotector.g.c.c("TPService.State"))) {
            TPService.n("UI");
        }
        biz.obake.team.touchprotector.a.b();
    }

    /* access modifiers changed from: protected */
    public void onStop() {
        super.onStop();
        biz.obake.team.touchprotector.g.c.g("MainActivity.State", "Stopped");
    }
}
